home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / bbs / cit_src_7H21.lha / bio.c < prev    next >
C/C++ Source or Header  |  1997-07-27  |  5KB  |  210 lines

  1. /*
  2. *       bio.c
  3. *
  4. * User Biography Functions.
  5. */
  6. /*
  7. *       history
  8. *
  9. * 91Jun14 HAW  Created.
  10. */
  11. #include "ctdl.h"
  12. #include <dos.h>
  13. /*
  14. *       contents
  15. *
  16. * BioDirectory()    Gets a list of user biographies.
  17. * ClearBio()    This clears a bio from disk.
  18. * EditBio()   Edits a biography by a user.
  19. * GetBioInfo()    Gets a bio from disk.
  20. * SaveBioInfo()   Save a bio to disk.
  21. */
  22. extern CONFIG      cfg;   /* Lots an lots of variables    */
  23. extern logBuffer   logBuf;    /* Person buffer    */
  24. extern logBuffer   logTmp;    /* Person buffer    */
  25. extern MessageBuffer     msgBuf;
  26. extern char    haveCarrier;    /* Do we still got carrier?     */
  27. extern int     thisLog;
  28. extern char    *LCHeld, *WRITE_ANY, *READ_ANY;
  29. extern char    outFlag;    /* Output flag     */
  30. extern char    onConsole;
  31. extern char    MsgEntryType;
  32. /**
  33.   InitBio()
  34.   This function will check to see if the bioArea exists and
  35.   will create it if it does not.
  36. **/
  37. void InitBio()
  38.   {
  39.   if( access(cfg.bioArea.saDirname, F_OK)) return;
  40.   mkdir((char *)&cfg.bioArea.saDirname);
  41.   }
  42. /*
  43. * EditBio()
  44. *
  45. * This function allows the editing of a biography.  If a biography already
  46. * exists then an option is offered to edit that rather than create a new
  47. * biography.  NB: "null" biographies are not saved but are rather completely
  48. * deleted so they don't show up on .M?
  49. */
  50. void EditBio()
  51.   {
  52.   char name[15];
  53.   SYS_FILE bio;
  54.   doCR();
  55.   sPrintf(name, "%d.bio", thisLog);
  56.   MakeBioName(bio, name);
  57.   if (cfg.BoolFlags.debug)
  58.     {
  59.     splitF(NULL,"EditBio:%s\n",bio);
  60.     };
  61.   if (access(bio, 0) == 0)
  62.     {
  63.     if (getYesNo("EDBIOS"))
  64.       {
  65.       GetBioInfo(thisLog);
  66.  
  67.       }
  68.     else msgBuf.mbtext[0] = 0;
  69.  
  70.     }
  71.   else msgBuf.mbtext[0] = 0;
  72.  
  73.   Output_Citadel_Message("BIONOV",NULL,NULL,NULL);
  74.   HelpIfPresent("biosys.blb");
  75.   MsgEntryType = BIO_ENTRY;
  76.   Output_Citadel_Message("MYBIOS",NULL,NULL,NULL);
  77.   doCR();
  78.   CleanEnd(msgBuf.mbtext);
  79.   mPrintf("%s", msgBuf.mbtext);
  80.   outFlag = OUTOK;
  81.   if (GetBalance(ASCII, msgBuf.mbtext, MAXTEXT-50) && onLine())
  82.     {
  83.     CleanEnd(msgBuf.mbtext);
  84.     if (strLen(msgBuf.mbtext) < 3)
  85.     ClearBio(thisLog);
  86.     else SaveBioInfo(thisLog);
  87.  
  88.     }
  89.  
  90.   }
  91. /*
  92. * GetBioInfo()
  93. *
  94. * This function handles the mechanics of getting biographical info.  It
  95. * handles the encryption.
  96. */
  97. char GetBioInfo(int which)
  98.   {
  99.   char name[15];
  100.   SYS_FILE bio;
  101.   FILE *fd;
  102.   long size;
  103.   sPrintf(name, "%d.bio", which);
  104.   MakeBioName(bio, name);
  105.   if (cfg.BoolFlags.debug)
  106.     {
  107.     splitF(NULL,"GetBio:%s\n",bio);
  108.     };
  109.   if ((fd = fopen(bio, READ_ANY)) != NULL)
  110.     {
  111.     totalBytes(&size, fd);
  112.     size++;       /* include NULL byte */
  113.     fread(msgBuf.mbtext, (int) size, 1, fd);
  114.     crypte(msgBuf.mbtext, (int) size, which);
  115.     fclose(fd);
  116.     return TRUE;
  117.  
  118.     }
  119.   msgBuf.mbtext[0] = 0;
  120.   return FALSE;
  121.  
  122.   }
  123. /*
  124. * SaveBioInfo()
  125. *
  126. * This function handles the mechanics of saving biographical info.  This
  127. * includes encrypting the bio before saving it.
  128. */
  129. void SaveBioInfo(int which)
  130.   {
  131.   char name[15];
  132.   SYS_FILE bio;
  133.   FILE *fd;
  134.   int size;
  135.   sPrintf(name, "%d.bio", which);
  136.   MakeBioName(bio, name);
  137.   if (cfg.BoolFlags.debug)
  138.     {
  139.     splitF(NULL,"SaveBio:%s\n",bio);
  140.     };
  141.   if ((fd = fopen(bio, WRITE_ANY)) != NULL)
  142.     {
  143.     size = strLen(msgBuf.mbtext) + 1; /* include NULL byte */
  144.     crypte(msgBuf.mbtext, (int) size, which);
  145.     fwrite(msgBuf.mbtext, (int) size, 1, fd);
  146.     crypte(msgBuf.mbtext, (int) size, which);
  147.     fclose(fd);
  148.  
  149.     }
  150.   else msgBuf.mbtext[0] = 0;
  151.  
  152.   }
  153. /*
  154. * ClearBio()
  155. *
  156. * This clears out a biography.
  157. */
  158. void ClearBio(int which)
  159.   {
  160.   char name[15];
  161.   SYS_FILE bio;
  162.   sPrintf(name, "%d.bio", which);
  163.   MakeBioName(bio, name);
  164.   if (cfg.BoolFlags.debug)
  165.     {
  166.     splitF(NULL,"ClearBio:%s\n",bio);
  167.     };
  168.   unlink(bio);
  169.  
  170.   }
  171. static  void ShowBioName(DirEntry *);
  172. /*
  173. * BioDirectory()
  174. *
  175. * This shows who's written biographies.  Rather ugly since we're between
  176. * major releases.  If we do another major release we should clean out
  177. * that call to MoveToBioDirectory().
  178. */
  179. void BioDirectory()
  180.   {
  181.   if (cfg.BoolFlags.debug)
  182.     {
  183.     splitF(NULL,"BioArea:%s\n",cfg.bioArea.saDirname);
  184.     };
  185.   MoveToBioDirectory();
  186.   if (wildCard(ShowBioName, "*.bio", FALSE, "", FALSE) == 0)
  187.     {
  188.     Output_Citadel_Message("NOBIOS",NULL,NULL,NULL);
  189.     }
  190.   else mPrintf("\b\b. \n ");
  191.   homeSpace();
  192.  
  193.   }
  194. /*
  195. * ShowBioName()
  196. *
  197. * This internal function shows the name of a person with a bio.  It is called
  198. * in connection with RunList() (see above).
  199. */
  200. static void ShowBioName(DirEntry *entry)
  201.   {
  202.   char *dot;
  203.   if ((dot = strchr(entry->unambig, '.')) == NULL) return;
  204.   *dot = 0;
  205.   getLog(&logTmp, atoi(entry->unambig));
  206.   if (logTmp.lbflags.L_INUSE)
  207.   mPrintf("%s, ", logTmp.lbname);
  208.  
  209.   }
  210.